package com.hemaapp.yjnh.bean;

import java.io.Serializable;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.uu.utils.uuUtils;

import xtom.frame.XtomObject;
import xtom.frame.exception.DataParseException;

/**田主信息,简介，只用于列表显示
 * @author ZhangGuiyou
 * Date: 2015-8-7 11:21
 */
public class Client extends XtomObject implements Serializable {

	private static final long serialVersionUID = 1L;

	private String client_id;// 用户id
    private String nickname;// 昵称
	private String avatar;// 头像
	private String starscore;// 星数
	private String distance;// 距离
	private String lng;
	private String lat;
	private String mu_num;// 土地亩数
	private String price;// 价格
	private String good_names;// 作物种类
	private String imgItems;// 农家产品图片列表
	private ArrayList<ImageItem> items = new ArrayList<ImageItem>();

	public Client(JSONObject jsonObject) throws DataParseException {
		if (jsonObject != null) {
			try {
				client_id = get(jsonObject, "client_id");
				nickname = get(jsonObject, "nickname");
				avatar = get(jsonObject, "avatar");
				starscore = get(jsonObject, "starscore");
				distance = get(jsonObject, "distance");
				lng = get(jsonObject, "lng");
				lat = get(jsonObject, "lat");
				mu_num = get(jsonObject, "mu_num");
				price = uuUtils.formatAfterDot2(get(jsonObject, "price"));
				good_names = get(jsonObject, "good_names");
				imgItems = get(jsonObject, "imgItems");
				if (null != imgItems && !imgItems.isEmpty()) {
					JSONArray jsons = new JSONArray(imgItems);
					for (int i = 0; i < jsons.length(); i++) {
	                    JSONObject child = jsons.getJSONObject(i);
	                    ImageItem item = new ImageItem(child);
	                    items.add(item);
	                }
				}

				log_i(toString());
			} catch (JSONException e) {
				throw new DataParseException(e);
			}
		}
	}

	@Override
	public String toString() {
		return "Client [client_id=" + client_id + ", nickname=" + nickname
				+ ", avatar=" + avatar + ", starscore=" + starscore + ", lng="
				+ lng + ", lat=" + lat + ", mu_num=" + mu_num + ", price="
				+ price + ", good_names=" + good_names + ", imgItems="
				+ imgItems + ", items=" + items + "]";
	}

	public String getLng() {
		return lng;
	}

	public String getNickname() {
		return nickname;
	}

	public String getAvatar() {
		return avatar;
	}

	public String getStarscore() {
		return starscore;
	}

	public String getDistance() {
		return distance;
	}

	public String getMu_num() {
		return mu_num;
	}

	public String getPrice() {
		return price;
	}

	public String getGood_names() {
		return good_names;
	}

	public String getImgItems() {
		return imgItems;
	}

	public String getLat() {
		return lat;
	}

	/**
	 * @return the client_id
	 */
	public String getClient_id() {
		return client_id;
	}

	public ArrayList<ImageItem> getItems() {
		return items;
	}
}
